<!DOCTYPE HTML>
<html>
<head>
<#include "/adminPage/common.html"/>
<style type="text/css">
.layui-form-label {
	width: 150px;
}

.layui-input-block {
	margin-left: 180px;
}
</style>
</head>
<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">

		<#include "/adminPage/header.html"/>
		<#include "/adminPage/menu.html"/>

		<div class="layui-body">
			<!-- 内容主体区域 -->
			<div style="padding: 15px">
				<fieldset class="layui-elem-field layui-field-title">
					<legend>反向代理</legend>
				</fieldset>

				<form action="${ctx}/adminPage/server" id="searchForm" method="post">
					<div class="layui-form">
						<div class="layui-inline">
							<button type="button" class="layui-btn layui-btn-normal" onclick="add()">添加反向代理</button>
						</div>

						<div class="layui-inline">
							<label class="layui-form-label">关键字</label>
						</div>
						<div class="layui-input-inline">
							<input type="text" name="keywords" class="layui-input" value="${keywords}">
						</div>

						<div class="layui-inline">
							<label class="layui-form-label">类型</label>
						</div>
						<div class="layui-input-inline">
							<select name="type">
								<option value="">--全部--</option>
								<option value="0" ${(type==0)?string('selected','')}>代理http</option>
								<option value="1" ${(type==1)?string('selected','')}>静态html</option>
							</select>
						</div>
						<button type="button" class="layui-btn" onclick="search()">搜索</button>

						<input type="hidden" name="curr" value="${page.curr}">
					</div>
				</form>

				<table class="layui-table">
					<thead>
						<tr>
							<th>监听端口</th>
							<th>监听域名</th>
							<th>类型</th>
							<th>开启ssl</th>
							<th>ssl文件路径</th>
							<th>http自动跳转https</th>
							<th>代理目标url</th>
							
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<#list page.records as ext>
						<tr>
							<td>${ext.server.listen}</td>
							<td>${ext.server.serverName}</td>
						
							<td>
								<#if ext.server.type==0>代理http </#if>
								<#if ext.server.type==1>静态html </#if>
							</td>
							<td>
								<#if ext.server.ssl==0>否</#if>
								<#if ext.server.ssl==1>是</#if>
							</td>
							<td>
								<#if ext.server.ssl==1> pem: ${ext.server.pem} <br> key: ${ext.server.key} </#if>
							</td>
							<td>
								<#if ext.server.ssl==1>
									<#if ext.server.rewrite==0>否</#if>
									<#if ext.server.rewrite==1>是</#if>
								</#if>
							</td>
							<td>
								<#if ext.server.type==0>
									<#if ext.server.proxyPassType == 0>
										${ext.server.proxyPass}
									</#if>
									<#if ext.server.proxyPassType == 1>
										负载均衡: ${ext.upstream.name}
									</#if>
								</#if>
								<#if ext.server.type==1>${ext.server.root}</#if>
							</td>
							<td>
								<button class="layui-btn layui-btn-sm" onclick="edit('${ext.server.id}')">编辑</button>
								<button class="layui-btn layui-btn-danger layui-btn-sm" onclick="del('${ext.server.id}')">删除</button>
							</td>
						</tr>
						</#list>
					</tbody>
				</table>
				<div id="pageInfo"></div>
			</div>
		</div>
	</div>

	<div style="height: 0px; width: 0px; overflow: hidden;">
		<!-- 弹出框 -->
		<div class="layui-form" id="windowDiv" style="padding: 15px; display: none">
			<form id="addForm">
				<input type="hidden" name="id" id="id">
				
				<div class="layui-form-item">
					<label class="layui-form-label">监听端口</label>
					<div class="layui-input-block">
						<input type="number" name="listen" id="listen" class="layui-input">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">监听域名</label>
					<div class="layui-input-block">
						<input type="text" name="serverName" id="serverName" class="layui-input" placeholder="例: www.sina.com 不填为监听所有域名">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">代理类型</label>
					<div class="layui-input-block">
						<select name="type" id="type" lay-filter="type">
							<option value="0">代理http</option>
							<option value="1">静态html</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">开启ssl</label>
					<div class="layui-input-block">
						<select name="ssl" id="ssl" lay-filter="ssl">
							<option value="0">否</option>
							<option value="1">是</option>
						</select>
					</div>
				</div>
				
				<div id="pemDiv" style="display: none;">
					<div class="layui-form-item">
						<label class="layui-form-label">pem文件路径</label>
						<div class="layui-input-block">
							<button type="button" class="layui-btn layui-btn-sm" id="pemBtn">上传pem文件</button>
							<input type="hidden" name="pem" id="pem" class="layui-input">
							<div class="layui-form-mid layui-word-aux" id="pemPath"></div>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">key文件路径</label>
						<div class="layui-input-block">
							<button type="button" class="layui-btn layui-btn-sm" id="keyBtn">上传key文件</button>
							<input type="hidden" name="key" id="key" class="layui-input">
							<div class="layui-form-mid layui-word-aux" id="keyPath"></div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label">http自动跳转https</label>
						<div class="layui-input-block">
							<select name="rewrite" id="rewrite">
								<option value="1">是</option>
								<option value="0">否</option>
							</select>
						</div>
					</div>
				</div>
				
				<div id="targetDiv">
					
					<div class="layui-form-item">
						<label class="layui-form-label">代理目标类型</label>
						<div class="layui-input-block">
							<select name="proxyPassType" id="proxyPassType" lay-filter="proxyPassType">
								<option value="0">url</option>
								<option value="1">负债均衡</option>
							</select>
						</div>
					</div>
				
				
					<div class="layui-form-item" id="url">
						<label class="layui-form-label">url</label>
						<div class="layui-input-block">
							<input type="text" name="proxyPass" id="proxyPass" class="layui-input" placeholder="例: http://127.0.0.1:8080">
						</div>
					</div>
					
					<div class="layui-form-item"  id="ups">
						<label class="layui-form-label">负载均衡</label>
						<div class="layui-input-block">
							<select name="upstreamId" id="upstreamId">
								<#list upstreamList as upstream>
									<option value="${upstream.id}">${upstream.name}</option>
								</#list>
							</select>
						</div>
					</div>
					
				</div>

				<div id="rootDiv" style="display: none;">
					<div class="layui-form-item">
						<label class="layui-form-label">静态根目录</label>
						<div class="layui-input-block">
							<input type="text" name="root" id="root" class="layui-input" placeholder="例: /home/www">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<button type="button" class="layui-btn layui-btn-normal" onclick="addOver()">提交</button>
					<button type="button" class="layui-btn" onclick="layer.closeAll()">关闭</button>
				</div>
			</form>
		</div>

	</div>

	<#include '/adminPage/script.html'/>
	<script src="${ctx}/js/adminPage/server/index.js?v=${jsrandom}" type="text/javascript"></script>
</body>


</html>